This invention relates to self calibrating and recalibrating an optical sensor to measure piston rod displacement, thereby enabling initial field calibration and recalibration to correct for wear and damage, and proximity sensors, time of flight sensors, cumulative relative displacement are used to estimate the piston rod absolute displacement and reduce the number of spatially unique calibration positions needed to compare in order to determine the piston rod absolute displacement, thereby reducing memory storage and computational resources required, which enable closely spaced or continuous calibration positions, and the use of naturally occurring speckle patterns as calibration positions reduce the need to use marked encoded sequences as calibration positions.